package com.stylefeng.guns.modular.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.CurFengkou;
import com.stylefeng.guns.modular.system.service.ICurFengkouService;
import com.stylefeng.guns.modular.system.warpper.CurFengKouWarpper;

/**
 * 当日风口控制器
 *
 * @author fengshuonan
 * @Date 2018-07-17 17:02:22
 */
@Controller
@RequestMapping("/curFengkou")
public class CurFengkouController extends BaseController {

    private String PREFIX = "/system/curFengkou/";

    @Autowired
    private ICurFengkouService curFengkouService;

    /**
     * 跳转到当日风口首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "curFengkou.html";
    }

    /**
     * 跳转到添加当日风口
     */
    @RequestMapping("/curFengkou_add")
    public String curFengkouAdd() {
        return PREFIX + "curFengkou_add.html";
    }

    /**
     * 跳转到修改当日风口
     */
    @RequestMapping("/curFengkou_update/{curFengkouId}")
    public String curFengkouUpdate(@PathVariable Integer curFengkouId, Model model) {
        CurFengkou curFengkou = curFengkouService.selectById(curFengkouId);
        model.addAttribute("item",curFengkou);
        LogObjectHolder.me().set(curFengkou);
        return PREFIX + "curFengkou_edit.html";
    }

    /**
     * 获取当日风口列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String date) {
    	Page<CurFengkou> page = new PageFactory<CurFengkou>().defaultPage();
    	List<Map<String, Object>> gdhs = curFengkouService.selectMapsByDm(page,date);
    	page.setRecords((List<CurFengkou>) new CurFengKouWarpper(gdhs).warp());
        return super.packForBT(page);
    }

    /**
     * 新增当日风口
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(CurFengkou curFengkou) {
        curFengkouService.insert(curFengkou);
        return SUCCESS_TIP;
    }

    /**
     * 删除当日风口
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer curFengkouId) {
        curFengkouService.deleteById(curFengkouId);
        return SUCCESS_TIP;
    }

    /**
     * 修改当日风口
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(CurFengkou curFengkou) {
        curFengkouService.updateById(curFengkou);
        return SUCCESS_TIP;
    }

    /**
     * 当日风口详情
     */
    @RequestMapping(value = "/detail/{curFengkouId}")
    @ResponseBody
    public Object detail(@PathVariable("curFengkouId") Integer curFengkouId) {
        return curFengkouService.selectById(curFengkouId);
    }
}
